package com.gitee.dolt.database.validator;

import com.baomidou.mybatisplus.extension.service.IService;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * 字段唯一约束，不支持锁
 *
 * @author LYH
 */
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ColumnUniqueConstraintValidator.class)
public @interface ColumnUnique {

    String message() default "属性[{property}]对应数据已存在";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 具体服务类
     *
     * @return
     */
    Class<? extends IService> service();

    /**
     * id
     *
     * @return
     */
    String id() default "id";

    /**
     * 属性字段
     *
     * @return
     */
    String property();

    /**
     * 是否支持修改
     *
     * @return
     */
    boolean supportUpdate() default true;

    @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @interface List {
        ColumnUnique[] value();
    }


}